package com.liuwang.meal.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
/**
 * 
 * @author 陈江根
 * 数据库工具类
 */
public class DBHelper extends SQLiteOpenHelper{
    // 数据库名称常量
    private static final String DATABASE_NAME = "Meal.db";
    // 数据库版本常量
    private static final int DATABASE_VERSION = 1;
	// 构造方法
	public DBHelper(Context context) {
		// 创建数据库
		super(context, DATABASE_NAME,null, DATABASE_VERSION);
	}

	// 创建时调用
	public void onCreate(SQLiteDatabase db) {
		//创建表
		db.execSQL("CREATE TABLE " + Users.TABLE + " ("
				+ Users._ID + " INTEGER PRIMARY KEY,"
				+ Users.ACCOUNT + " TEXT,"
				+ Users.PASSWORD + " TEXT,"
				+ Users.NAME + " TEXT,"
				+ Users.PERMISSION + " INTEGER,"
				+ Users.REMARK + " TEXT"
				+ ");");
		//插入数据
		db.execSQL("insert into "+Users.TABLE+" (account,password,name,permission,remark) " + 
				"values ('waiter','123456','服务员','0','服务员帐号')");
		db.execSQL("insert into "+Users.TABLE+" (account,password,name,permission,remark) " + 
				"values ('chef','123456','厨师','1','厨师帐号')");
		
		
		//创建表
		db.execSQL("CREATE TABLE " + Tables.TABLE+ " ("
				+ Tables._ID + " INTEGER PRIMARY KEY,"
				+ Tables.NUM + " INTEGER,"
				+ Tables.TYPE + " TEXT,"
				+ Tables.COUNT + " INTEGER,"
				+ Tables.REMARK + " TEXT"
				+ ");");
		//插入数据
		db.execSQL("insert into "+Tables.TABLE+" (num,type,count,remark) " + 
				"values ('1','方桌','4','')");
		db.execSQL("insert into "+Tables.TABLE+" (num,type,count,remark) " + 
				"values ('2','圆桌','8','')");
		db.execSQL("insert into "+Tables.TABLE+" (num,type,count,remark) " + 
				"values ('3','包间','16','')");
		
		//创建表
		db.execSQL("CREATE TABLE " + MenuTypes.TABLE+ " ("
				+ MenuTypes._ID + " INTEGER PRIMARY KEY,"
				+ MenuTypes.NAME + " TEXT"
				+ ");");
		//插入数据
		db.execSQL("insert into "+MenuTypes.TABLE+" (name) " + 
				"values ('今日特价')");
		db.execSQL("insert into "+MenuTypes.TABLE+" (name) " + 
				"values ('招牌菜')");
		db.execSQL("insert into "+MenuTypes.TABLE+" (name) " + 
				"values ('主菜')");
		db.execSQL("insert into "+MenuTypes.TABLE+" (name) " + 
				"values ('素菜')");
		db.execSQL("insert into "+MenuTypes.TABLE+" (name) " + 
				"values ('凉菜')");
		db.execSQL("insert into "+MenuTypes.TABLE+" (name) " + 
				"values ('煲汤')");
		db.execSQL("insert into "+MenuTypes.TABLE+" (name) " + 
				"values ('酒水')");
		
		//创建表
		db.execSQL("CREATE TABLE " + Menus.TABLE+ " ("
				+ Menus._ID + " INTEGER PRIMARY KEY,"
				+ Menus.TYPE_ID + " INTEGER,"
				+ Menus.NAME + " TEXT,"
				+ Menus.DESCRIPTION + " TEXT,"
				+ Menus.PRICE + " INTEGER,"
				+ Menus.UNIT + " TEXT,"
				+ Menus.PIC + " TEXT,"
				+ Menus.REMARK + " TEXT"
				+ ");");
		//插入数据
		db.execSQL("insert into "+Menus.TABLE+" ("+Menus.TYPE_ID+","+Menus.NAME+","+Menus.DESCRIPTION+","+Menus.PRICE+","+Menus.UNIT+","+Menus.PIC+","+Menus.REMARK+") " + 
				"values ('1','麻辣鱼','1','11','份','1.jpg','')");
		db.execSQL("insert into "+Menus.TABLE+" ("+Menus.TYPE_ID+","+Menus.NAME+","+Menus.DESCRIPTION+","+Menus.PRICE+","+Menus.UNIT+","+Menus.PIC+","+Menus.REMARK+") " + 
				"values ('1','湖南酱板鸭','2','14','份','2.jpg','')");
		db.execSQL("insert into "+Menus.TABLE+" ("+Menus.TYPE_ID+","+Menus.NAME+","+Menus.DESCRIPTION+","+Menus.PRICE+","+Menus.UNIT+","+Menus.PIC+","+Menus.REMARK+") " + 
				"values ('1','油炸香菇','3','16','份','3.jpg','')");
		db.execSQL("insert into "+Menus.TABLE+" ("+Menus.TYPE_ID+","+Menus.NAME+","+Menus.DESCRIPTION+","+Menus.PRICE+","+Menus.UNIT+","+Menus.PIC+","+Menus.REMARK+") " + 
				"values ('1','红烧茄子','4','17','份','4.jpg','')");
		db.execSQL("insert into "+Menus.TABLE+" ("+Menus.TYPE_ID+","+Menus.NAME+","+Menus.DESCRIPTION+","+Menus.PRICE+","+Menus.UNIT+","+Menus.PIC+","+Menus.REMARK+") " + 
				"values ('1','肉丁鸡蛋','5','35','份','5.jpg','')");
		db.execSQL("insert into "+Menus.TABLE+" ("+Menus.TYPE_ID+","+Menus.NAME+","+Menus.DESCRIPTION+","+Menus.PRICE+","+Menus.UNIT+","+Menus.PIC+","+Menus.REMARK+") " + 
				"values ('1','湖南酸辣凤翅','6','37','份','6.jpg','')");
		db.execSQL("insert into "+Menus.TABLE+" ("+Menus.TYPE_ID+","+Menus.NAME+","+Menus.DESCRIPTION+","+Menus.PRICE+","+Menus.UNIT+","+Menus.PIC+","+Menus.REMARK+") " + 
				"values ('1','海鲜','7','38','份','7.jpg','')");
		db.execSQL("insert into "+Menus.TABLE+" ("+Menus.TYPE_ID+","+Menus.NAME+","+Menus.DESCRIPTION+","+Menus.PRICE+","+Menus.UNIT+","+Menus.PIC+","+Menus.REMARK+") " + 
				"values ('2','海鲜','7','19','份','7.jpg','')");
		db.execSQL("insert into "+Menus.TABLE+" ("+Menus.TYPE_ID+","+Menus.NAME+","+Menus.DESCRIPTION+","+Menus.PRICE+","+Menus.UNIT+","+Menus.PIC+","+Menus.REMARK+") " + 
				"values ('3','红烧牛肉','8','20','份','8.jpg','')");
		db.execSQL("insert into "+Menus.TABLE+" ("+Menus.TYPE_ID+","+Menus.NAME+","+Menus.DESCRIPTION+","+Menus.PRICE+","+Menus.UNIT+","+Menus.PIC+","+Menus.REMARK+") " + 
				"values ('4','红烧茄子','4','21','份','4.jpg','')");
		db.execSQL("insert into "+Menus.TABLE+" ("+Menus.TYPE_ID+","+Menus.NAME+","+Menus.DESCRIPTION+","+Menus.PRICE+","+Menus.UNIT+","+Menus.PIC+","+Menus.REMARK+") " + 
				"values ('5','地三鲜','9','22','份','9.jpg','')");
		db.execSQL("insert into "+Menus.TABLE+" ("+Menus.TYPE_ID+","+Menus.NAME+","+Menus.DESCRIPTION+","+Menus.PRICE+","+Menus.UNIT+","+Menus.PIC+","+Menus.REMARK+") " + 
				"values ('6','乌鸡汤','10','23','份','10.jpg','')");
		db.execSQL("insert into "+Menus.TABLE+" ("+Menus.TYPE_ID+","+Menus.NAME+","+Menus.DESCRIPTION+","+Menus.PRICE+","+Menus.UNIT+","+Menus.PIC+","+Menus.REMARK+") " + 
				"values ('7','啤酒','11','24','份','11.jpg','')");
		
		//创建表
		db.execSQL("CREATE TABLE " + Orders.TABLE+ " ("
				+ Orders._ID + " INTEGER PRIMARY KEY,"
				+ Orders.ORDERTIME + " TEXT,"
				+ Orders.USERID + " INTEGER,"
				+ Orders.TABLEID + " INTEGER,"
				+ Orders.ISPAY + " INTEGER,"
				+ Orders.PERSONNUM + " INTEGER,"
				+ Orders.REMARK + " TEXT"
				+ ");");
		//插入数据
//		db.execSQL("insert into "+Orders.TABLE+" (orderTime,userID,tableID,isPay,personNum,remark) " + 
//				"values ('2013-3-23 12:12:12','1','1','1','4','')");
		
		//创建表
		db.execSQL("CREATE TABLE " + OrderDetails.TABLE+ " ("
				+ OrderDetails._ID + " INTEGER PRIMARY KEY,"
				+ OrderDetails.ORDERID+ " INTEGER,"
				+ OrderDetails.MENUID+ " INTEGER,"
				+ OrderDetails.NUM + " INTEGER,"
				+ OrderDetails.STATE + " INTEGER,"
				+ OrderDetails.REMARK + " TEXT"
				+ ");");
		//插入数据
//		db.execSQL("insert into "+OrderDetails.TABLE+" (orderID,menuID,num,state,remark) " + 
//				"values ('1','1','1','2','')");
		
//        db.execSQL("CREATE TABLE " + TABLES_TABLE_NAME1 + " ("
//                + Tables._ID + " INTEGER PRIMARY KEY,"
//                + Tables.NUM + " TEXT,"
//                + Tables.REMARK + " TEXT"
//                + ");");
        
//        db.execSQL("CREATE TABLE " + TABLES_TABLE_NAME2 + " ("
//                + Menus._ID + " INTEGER PRIMARY KEY,"
//                + Menus.TYPE_ID + " INTEGER,"
//                + Menus.NAME + " TEXT,"
//                + Menus.PRICE + " INTEGER,"
//                + Menus.PIC + " TEXT,"
//                + Menus.REMARK + " TEXT"
//                + ");");
	}

	// 版本更新时调用
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// 删除表
		db.execSQL("DROP TABLE IF EXISTS UserTal");
		db.execSQL("DROP TABLE IF EXISTS TableTbl");
		db.execSQL("DROP TABLE IF EXISTS MenuTypeTal");
		db.execSQL("DROP TABLE IF EXISTS MenuTal");
		db.execSQL("DROP TABLE IF EXISTS OrderTal");
		db.execSQL("DROP TABLE IF EXISTS OrderDetailTal");
        onCreate(db);
	}

}
